<?php
namespace app\common\model;

use think\Model;
use think\Cache;
class CodeMap extends BaseModel
{
    /**
     *  获取信息
     */
    public function get_value($key, $k_value = "")
    {
        $code_map_list = unserialize(Cache::get("code_map"));
        if (empty($code_map_list)) {
            $code_map_list = $this->all()->toArray();
            Cache::set("code_map", serialize($code_map_list));
        }
        $code_arr = [];
        if (empty($k_value)) {
            foreach ($code_map_list as $code) {
                if ($code["group_name"] == $key) {
                    array_push($code_arr, $code);
                }
            }
        } else {
            foreach ($code_map_list as $code) {
                if ($code["group_name"] == $key&&$code["m_value"] ==$k_value ) {
                    $code_arr=$code;
                    break;
                }
            }
        }

        return  $code_arr;
    }
}
